{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((5000, 401), (5000, 1), (401, 25), (26, 10))"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 导入数据集\n",
    "x_data=np.hstack((np.ones((5000,1)),np.array(pd.read_csv('X_data.csv',header=None))))\n",
    "y_label=np.array(pd.read_csv('y_label.csv',header=None))\n",
    "theta1=np.array(pd.read_csv('Theta1.csv',header=None)).T\n",
    "theta2=np.array(pd.read_csv('Theta2.csv',header=None)).T\n",
    "x_data.shape,y_label.shape,theta1.shape,theta2.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5000, 25)"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 第一层网络\n",
    "x1=np.matmul(x_data,theta1)\n",
    "x1=1/(1+np.exp(-x1))\n",
    "x1.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5000, 10)"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 第二层网络\n",
    "x1=np.hstack((np.ones((x1.shape[0],1)),x1))\n",
    "x2=np.matmul(x1,theta2)\n",
    "x2=1/(1+np.exp(-x2))\n",
    "\n",
    "x2.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9752\n"
     ]
    }
   ],
   "source": [
    "y=np.argmax(x2,axis=1)+1\n",
    "acc=(y.reshape(-1,1)==y_label).sum()/y.shape[0]#求精度\n",
    "print(acc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
